import 'package:flutter/material.dart';
import 'package:flutter_aygsh/base/Constant.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class LocalNavWebWidget extends StatefulWidget {
  String title;
  String url;

  LocalNavWebWidget(this.url, this.title);
  @override
  _LocalNavWebWidgetState createState() =>
      _LocalNavWebWidgetState(title: title, url: url);
}

class _LocalNavWebWidgetState extends State<LocalNavWebWidget> {
  String url;
  String title;
  bool s=false;
  @override
  void initState() {
    super.initState();
    print(url);
    final flutterWebviewPlugin = new FlutterWebviewPlugin();
    if(!url.contains("0731")){
flutterWebviewPlugin.onUrlChanged.listen((String url) {
      if(s){
        Navigator.of(context).pop("1");
      }
      else
      s=true;
    });
    }
    
  }

  _LocalNavWebWidgetState({this.url, this.title});
  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
        url: url,
        appBar: new AppBar(
          title: new Text(
            "$title",
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black),
          ),
          elevation: 0.5,
          backgroundColor: Colors.white,
          brightness: Brightness.light,
          centerTitle: true,
          iconTheme: new IconThemeData(color: Colors.black),
        ),
        withJavascript: true,

        //当WebView没加载出来前显示
        initialChild: Container(
          color: Colors.white,
          child: Center(
            child: Text("正在加载中...."),
          ),
        ));
  }
}
